const {ccclass, property} = cc._decorator;
import BattleCardBo from "../model/BattleCardBo";
import CardStatusBo from "../model/CardStatusBo";


@ccclass
export default class BattleCard extends cc.Component {

    HPLabel: cc.Label;
    status : CardStatusBo = null;

    init(battleCardBo:BattleCardBo, HPLabel: cc.Label){
        this.HPLabel = HPLabel; 
        this.status = new CardStatusBo(battleCardBo);
        this.updateCardStatus();
    }
    onLoad() {
        this.initAction();
    }

    updateCardStatus(){
        // this.node.getComponent(cc.Label).string = `HP: ${this.status.health}/${this.status.base.health}`;
        this.HPLabel.string = `HP: ${this.status.health}/${this.status.base.health}`;
    }

    private _attackAction : cc.Action;

    statics={
        jumpAction:()=>{
        }
    }
    async initAction(){

        var jumpUp = cc.moveBy(0.2, cc.p(0, 30)).easing(cc.easeCubicActionOut());
        var jumpDown = cc.moveBy(0.2, cc.p(0, -30)).easing(cc.easeCubicActionIn());
        this._attackAction = cc.sequence(jumpUp, jumpDown);
    }

    getDmg():number{
        this.node.runAction(this._attackAction);
        return this.status.damage;
    }
    takeDmg(dmg:number){
        this.status.takeDmg(dmg);
        this.updateCardStatus();
    }


}

